export const formatTime = (date: Date) => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return (
    [year, month, day].map(formatNumber).join('/') +
    ' ' +
    [hour, minute, second].map(formatNumber).join(':')
  )
}
const formatNumber = (n: number) => {
  const s = n.toString()
  return s[1] ? s : '0' + s
}
// 判断value 是否有值
export const hasValue = (value: any): value is NonNullable<any> => {
  return value !== null && value !== undefined && value !== '';
};
// 创建转换函数，将 player 对象转换为具有 text 和 value 的新对象
export const convertToTextValueObject = (propertyText: string, propertyValue: string): { text: string; value: string } => ({
  text: propertyText,
  value: propertyValue,
});
//解析URL地址获取参数
export function parseURLParams(url: string): Record<string, string> {
  // 提取查询字符串
  const queryStartIndex = url.indexOf('?');
  const query = queryStartIndex !== -1 ? url.slice(queryStartIndex + 1) : '';

  // 解析查询字符串
  const params: Record<string, string> = {};
  query.split('&').forEach((param) => {
    const [key, value] = param.split('=');
    if (key && value) {
      params[decodeURIComponent(key)] = decodeURIComponent(value);
    }
  });

  return params;
}
